

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>网站设置</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/layadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/layadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <!-- <div class="layui-card-header">新增栏目</div> -->
          <div class="layui-card-body" pad15>
            
            <div class="layui-form" wid100 lay-filter="">
              <div class="layui-form-item">
                <label class="layui-form-label">分组名称<span style="color: red;">*</span></label>
                <div class="layui-input-block">
                  <input type="text" name="name" value="{$mess.name}" class="layui-input" lay-verify="required">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline" style="width: 80px;">
                  <input type="text" name="sort" lay-verify="number" value="{$mess.sort|default=999}" class="layui-input">
                  <input type="hidden" name="updid" value="{$mess.id}">
                </div>
                <!-- <div class="layui-form-mid layui-word-aux">本地开发一般推荐设置为 0，线上环境建议设置为 10。</div> -->
              </div>             
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit lay-filter="formSubmit">确认保存</button>
                 <button  class="layui-btn layui-btn-primary formCancel" >取消</button>
                </div>
              </div>
            </div>            
          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="/static/layadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '/static/layadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
    ,form = layui.form;
    
    //监听提交
    form.on('submit(formSubmit)', function(data){
      var field = data.field; //获取提交的字段
      var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
      // layer.msg('表单已提交');
      // console.log(field);
      //提交 Ajax 成功后，关闭当前弹层并重载表格
      $.post('/admin/filex/addCateDone/updid/'+field.updid, {name:field.name,sort:field.sort}, function(res){
        res=$.parseJSON(res);
        console.log(res.code);
        if(res.code == 200){
          layer.msg(res.msg, {
            icon: 1,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
          }, function(){
            // parent.layui.table.reload('test-table-toolbar'); //重载表格
            parent.location.reload();
            parent.layer.close(index); //再执行关闭 
          });                     
        }else{
          layer.msg(res.msg,{icon:2,time:2000});
        }        
      });      
    });
    $('.formCancel').on('click', function () {
          var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
          parent.layer.close(index); //再执行关闭 
        });
  })
  </script>
</body>
</html>